package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.Present;

public class PresentDAOImpl extends BaseHibernateDAOImpl<Present> implements PresentDAO {

	public Present getPresentByPresentID(String presentID) {
		Present present;
		try {
			present = (Present) getSession().get(Present.class, presentID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return present;
	}
	
	@SuppressWarnings("unchecked")
	public List<Present> getAllPresentByCondition(String hql) {
		List<Present> presents;
		try {
			Query query = getSession().createQuery("from Present" + hql);
			presents = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return presents;
	}

	@SuppressWarnings("unchecked")
	public List<Present> getAllPresentByConditionByPage(String hql, int currentPage, int lineSize) {
		List<Present> presents;
		try {
			Query query = getSession().createQuery("from Present" + hql);
			query.setFirstResult((currentPage - 1) * lineSize);
			query.setMaxResults(lineSize);
			presents = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return presents;
	}

}
